package org.swxjava.assembler.avm1;

import org.swxjava.assembler.ObjectCompiler;

public class AsObjectProperty {

	private AsObjectProperty nextProp;
	private AsVarString name;
	private ObjectCompiler value;

	public AsObjectProperty(AsVarString name, ObjectCompiler value) {
		this.name = name;
		this.value = value;
	}

	public void setNext(AsObjectProperty nextProp) {
		this.nextProp = nextProp;
	}
	
	public AsObjectProperty getNext() {
		return nextProp;
	}

	public ObjectCompiler name() {
		return name;
	}
	
	public ObjectCompiler value() {
		return value;
	}

	public boolean isComplex() {
		boolean complex = false;
		complex = (value instanceof AsArray || value instanceof AsObject);
		return complex;
	}
	
	public boolean isNew() {
		boolean isNew = false;
		isNew = (value instanceof AsClass);
		return isNew;
	}

	public int getByteSize() {
		int size = name.getByteSize();
		if(!this.isComplex()) {
			size += value.getByteSize();
			if (nextProp == null) {
				size += 5; // INT int(4) : Append number of object properties
			} else if(!this.isNew()) {
				// Stop calculating next byte size.
				size += nextProp.getByteSize();
			}
		}
		return size;
	}
}
